home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 2 / Amiga Tools 2.iso / dfue / avmnfax / rexx / handlefax.avm < prev    next >
Text File  |  1995-03-09  |  15KB  |  574 lines

  1. /* TITLE: avm:rexx/handlefax.avm */
  2. /* we want results! Otherwise, we wouldn't get anything from RESULT */
  3. options results
  4.  
  5. /* Need to make sure that stdtail.avm is also included */
  6. signal on halt
  7. signal on novalue
  8. signal on syntax
  9. signal on break_c
  10.  
  11. /* needed for some of the functions we use */
  12. call addlib("rexxsupport.library", 0, -30, 0)
  13.  
  14. /* a higher than normal priority since calls are important to us :) */
  15. call pragma('priority', 1)
  16.  
  17. /* ensure that commands are directed to the correct server */
  18. parse arg servername .
  19. address value servername
  20.  
  21.  
  22. parse arg servername mailbox .
  23. if symbol('mailbox') ~= 'VAR' | mailbox = '' then mailbox = 'manual'
  24. options failat 50
  25.  
  26. 'turnoffvoicemode'
  27.  
  28. 'assumemode' 'Unknown'
  29.  
  30. 'setserial' '19200' '8' 'N' '1' '7Wire'
  31. action = rc
  32. select
  33.   when action = 0 then nop
  34.   when action = 14 then nop
  35.   when action = 16 then nop
  36.   otherwise signal arexxerror
  37. end
  38.  
  39. isTrapFax:
  40. faxprogram = upper(getclip('AVMFaxProgram'))
  41. if faxprogram = 'TRAPFAX' then do
  42.  
  43. call showDebugger('Starting TrapFax reception.')
  44. call time('r')
  45. /*----------------------------------------*/
  46. address rexx 'setuptfax.avm'
  47. /*----------------------------------------*/
  48.  
  49. 'writeline' 'ATA'
  50.  
  51. address command "trapfax:tfaxdoor getty"
  52. call showDebugger('TrapFax reception ' || time('e'))
  53.  
  54. isGPFax:
  55. end; else if faxprogram = 'GPFAX' then do
  56.  
  57. call showDebugger('Starting GPFax reception.')
  58. call time('r')
  59.  
  60. address rexx_gpfax 'listen'
  61. address rexx_gpfax 'recfax'
  62. faxresult = rc
  63. address rexx_gpfax 'unlisten'
  64. call showDebugger('GPFax result is' faxresult)
  65. call showDebugger('GPFax done ' || time('e'))
  66.  
  67. isEFax:
  68. end; else if faxprogram = 'EFAX' then do
  69. /* create a unique filename */
  70. efaxFileName = makeUniqueFile()
  71. call time('r')
  72. address command 'avm:gnu/efax -p' servername '-r' voiceFile(mailbox, efaxFileName)
  73. efaxLength = time('e')
  74.  
  75. end
  76.  
  77. doneRecFax:
  78. 'delay' 2
  79. action = rc
  80. select
  81.   when action = 0 then nop
  82.   when action = 12 then signal stdabort
  83.   when action = 14 then signal stderror
  84.   when action = 16 then signal stderror
  85.   otherwise signal arexxerror
  86. end
  87.  
  88. 'writeline' 'AT+FCLASS=0'
  89.  
  90. 'readline' '2'
  91. action = rc
  92. if action = 0 then value = result
  93. select
  94.   when action = 0 then nop
  95.   when action = 10 then nop
  96.   when action = 12 then signal stdabort
  97.   when action = 14 then signal stderror
  98.   when action = 16 then signal stderror
  99.   otherwise signal arexxerror
  100. end
  101.  
  102. 'readline' '2'
  103. action = rc
  104. if action = 0 then value = result
  105. select
  106.   when action = 0 then nop
  107.   when action = 10 then nop
  108.   when action = 12 then signal stdabort
  109.   when action = 14 then signal stderror
  110.   when action = 16 then signal stderror
  111.   otherwise signal arexxerror
  112. end
  113.  
  114. createLog:
  115. handle = makeUniqueFile()
  116. call initLogEntry()
  117.  
  118. log.comment = 'Fax attempted.'
  119. log.type = 'Try_FAX'
  120. if faxprogram = 'GPFAX' then do
  121.   if faxresult <= 5 then signal gotfaxgpfax
  122. end; else if faxprogram = 'TRAPFAX' then do
  123.   call open('cfaxlstfl', 'trapfax:trapfax.log', 'r')
  124.   call open('cfaxnrfl', 'trapfax:incoming/trapfax.sequence', 'r')
  125.   cfaxnr = readln('cfaxnrfl')
  126.   cnewfaxnr = right(cfaxnr, 4, '0')
  127.  
  128.   do forever
  129.     cfax = readln('cfaxlstfl')
  130.     cfaxlsnr = right(left(cfax, 6), 4)
  131.     if cfaxlsnr = cfaxnr | eof('cfaxlstfl') then break
  132.   end
  133.   call close('cfaxlstfl'); call close('cfaxnrfl')
  134.   if left(cfax, 1) ~= 'E' then signal gotfaxtrapfax
  135. end; else if faxprogram = 'EFAX' then do
  136.  
  137. if exists(voiceFile(mailbox, efaxFileName) || '.001') then signal gotfaxefax
  138. end
  139.  
  140. signal finished
  141.  
  142. gotfaxgpfax:
  143. address rexx_gpfax 'reportlog' 1
  144. faxfilename = result
  145. log.filename = result
  146.  
  147. address rexx_gpfax 'reportlog' 6
  148. log.length = result
  149. address rexx_gpfax 'reportlog' 2
  150. log.comment = result 'page(s) received.'
  151.  
  152. address rexx_gpfax 'reportlog' 4
  153. log.returnnumber = result
  154. log.type = 'fax'
  155. signal finished
  156.  
  157. gotfaxtrapfax:
  158. faxfilename = 'trapfax:incoming/In-' || cfaxnr || '.FAX'
  159. log.filename = faxfilename
  160. myvar = right(left(cfax, 54), 5)
  161. myvar = (left(myvar, 2)*60) + (right(myvar, 2))
  162. log.length = myvar
  163. myvar = right(left(cfax, 47), 2); myvar = strip(myvar, 'L')
  164. log.comment = myvar 'page(s)'
  165. myvar = right(left(cfax, 45), 22)
  166. myvar = strip(myvar, 'T')
  167. log.returnnumber = myvar; log.type = 'fax'
  168. signal finished
  169.  
  170. gotfaxefax:
  171. log.filename = efaxFileName
  172. faxfilename = efaxFileName
  173. log.type = 'fax'
  174. log.length = efaxLength
  175. base = voiceFile(mailbox, efaxFileName) || '.'
  176. do i = 1 to 999
  177.   if ~exists(base || right(i, 3, '0')) then break
  178. end
  179. log.comment = i - 1 'page(s).'
  180.  
  181. log.returnNumber = getclip(upper(servername || '.faxid'))
  182. signal finished
  183.  
  184. finished:
  185. call saveLogEntry(mailbox, handle)
  186.  
  187. call loadMailbox(mailbox)
  188. if upper(log.type) = 'FAX' & mailbox.autofaxforwardb = 1 & mailbox.autofaxforwardscript ~= "" then do
  189.   handle = makeUniqueFile()
  190.   call initLogEntry(); log.origmailbox = mailbox
  191.   log.filename = voiceFile(mailbox, faxfilename); log.type = 'fax'
  192.   log.returnsendfunc = mailbox.autofaxforwardscript; log.returninterval = 5
  193.   log.returnretry = 3; log.returnnumber = mailbox.autofaxforward
  194.   call saveLogEntry('Outgoing', handle)
  195. end
  196.  
  197. exit
  198.  
  199. /* TITLE: avm:rexx/simplestdtail.avm */
  200. /* This is the standard tail */
  201. exit
  202.  
  203. exit
  204.  
  205. mailboxDir: procedure
  206.     parse arg mailbox
  207.  
  208.     return 'avm:' || mailbox || '/'
  209.  
  210. logFile: procedure
  211.     parse arg mailbox, magiccookie
  212.  
  213.     return 'avm:' || mailbox || '/logs/' || magiccookie
  214.  
  215. voiceFile: procedure
  216.     parse arg mailbox, magiccookie
  217.  
  218.         if (verify(magiccookie, '/:', 'M') = 0) then
  219.           return 'avm:' || mailbox || '/voices/' || magiccookie
  220.         else
  221.           return magiccookie
  222.  
  223. makeUniqueFile: procedure
  224.     if arg() ~= 0 then do
  225.         rc = "makeUniqueFile: bad args"
  226.         signal error
  227.     end
  228.     return address() || '.' || date('i') || '.' || time('s') || '.' || random(1, 999, time('s'))
  229.  
  230. convertToDate: procedure
  231.     if arg() ~= 1 then do
  232.         rc = "convertToDate: bad args"
  233.         signal error
  234.     end
  235.     parse arg timeInC
  236.  
  237.     actualTime = (timeInC - (2922)*86400) // (86400)
  238.     actualDate = (timeInC - actualTime - 2922*86400) % 86400
  239.  
  240.     return actualDate /* returning it in 'internal' format */
  241.  
  242. convertToTime: procedure
  243.     if arg() ~= 1 then do
  244.         rc = "convertToTime: bad args"
  245.         signal error
  246.     end
  247.     parse arg timeInC
  248.     
  249.     actualTime = (timeInC - (2922)*86400) // (86400)
  250.  
  251.     return actualTime
  252.  
  253. cTime: procedure
  254.     /* 2922 = 8*365 + 2 */
  255.     /* 86400 = 24*60*60 */
  256.     return (date('i')+2922)*86400 + time('s')
  257.  
  258. /* this returns a handle that you must use after initializing log. */
  259. initLogEntry: procedure expose log.
  260.     if arg() ~= 0 then do
  261.         rc = "initLogEntry: bad args"
  262.         signal error
  263.     end
  264.     
  265.     drop log.
  266.         log. = ''
  267.  
  268.         acidname = getclip(address() || 'CIDNAME')
  269.         acidnumber = getclip(address() || 'CIDNUMBER')
  270.  
  271.     /* 2922 = 8*365 + 2 */
  272.     /* 86400 = 24*60*60 */
  273.     log.time = (date('i')+2922)*86400 + time('s')
  274.     log.cidname = acidname
  275.     log.cidnumber = acidnumber
  276.  
  277.     return
  278.  
  279. loadLogEntry: procedure expose log.
  280.     if arg() ~= 2 then do
  281.         rc = "loadLogEntry: bad args"
  282.         signal error
  283.     end
  284.     parse arg mailbox, handle
  285.  
  286.         drop log.
  287.         log. = ''
  288.  
  289.     if ~exists(mailboxDir(mailbox)) then do
  290.         call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
  291.         return
  292.     end
  293.  
  294.     opened = open(handle, logFile(mailbox, handle), 'r')
  295.         if opened then do
  296.         call showDebugger('Loading entry' logFile(mailbox, handle))
  297.         do while ~eof(handle)
  298.             line = readln(handle)
  299.             parse upper var line variable '=' value
  300.             log.variable = value
  301.         end
  302.         call close(handle)
  303.     end; else call showDebugger('Could not load' logFile(mailbox, handle))
  304.     return
  305.  
  306. /* pass a handle here */
  307. saveLogEntry: procedure expose log.
  308.     if arg() ~= 2 then do
  309.         rc = "saveLogEntry: bad args"
  310.         signal error
  311.     end
  312.     parse arg mailbox, handle
  313.  
  314.     if ~exists(mailboxDir(mailbox)) then do
  315.         call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
  316.         return
  317.     end
  318.  
  319.     opened = open(handle, logFile(mailbox, handle), 'w')
  320.  
  321.     if opened then do
  322.         call showDebugger('Saving entry' logFile(mailbox, handle))
  323.         call writeln(handle, 'TYPE=' || log.type)
  324.         call writeln(handle, 'TIME=' || log.time)
  325.         call writeln(handle, 'LENGTH=' || log.length)
  326.  
  327.         call writeln(handle, 'ORIGMAILBOX=' || log.origmailbox)
  328.  
  329.         call writeln(handle, 'CIDNAME=' || log.cidname)
  330.         call writeln(handle, 'CIDNUMBER=' || log.cidnumber)
  331.  
  332.         call writeln(handle, 'COMMENT=' || log.comment)
  333.  
  334.         call writeln(handle, 'FILENAME=' || log.filename)
  335.         call writeln(handle, 'ALTFILENAME=' || log.altfilename)
  336.  
  337.         call writeln(handle, 'RETURNNUMBER=' || log.returnnumber)
  338.         call writeln(handle, 'RETURNSENDFUNC=' || log.returnsendfunc)
  339.         call writeln(handle, 'RETURNSTATUS=' || log.returnstatus)
  340.  
  341.         call writeln(handle, 'RETURNRETRY=' || log.returnretry)
  342.         call writeln(handle, 'RETURNINTERVAL=' || log.returninterval)
  343.  
  344.         call close(handle)
  345.         address rexx 'broadcast' 'addtomailbox' mailbox handle
  346.     end; else call showDebugger('Could not save' logFile(mailbox, handle))
  347.  
  348.     return
  349.  
  350. /* pass a handle here */
  351. updateLogEntry: procedure expose log.
  352.     if arg() ~= 2 then do
  353.         rc = "updateLogEntry: bad args"
  354.         signal error
  355.     end
  356.     parse arg mailbox, handle
  357.  
  358.     if ~exists(mailboxDir(mailbox)) then do
  359.         call showDebugger('Dir=' || mailboxDir(mailbox) 'does not exist')
  360.         return
  361.     end
  362.  
  363.     if ~exists(logFile(mailbox, handle)) then do
  364.         call showDebugger('Unable to update non-existent' logFile(mailbox, handle))
  365.         return
  366.     end
  367.     opened = open(handle, logFile(mailbox, handle), 'w')
  368.  
  369.     if opened then do
  370.         call showDebugger('Updating entry' logFile(mailbox, handle))
  371.         call writeln(handle, 'TYPE=' || log.type)
  372.         call writeln(handle, 'TIME=' || log.time)
  373.         call writeln(handle, 'LENGTH=' || log.length)
  374.  
  375.         call writeln(handle, 'ORIGMAILBOX=' || log.origmailbox)
  376.  
  377.         call writeln(handle, 'CIDNAME=' || log.cidname)
  378.         call writeln(handle, 'CIDNUMBER=' || log.cidnumber)
  379.  
  380.         call writeln(handle, 'COMMENT=' || log.comment)
  381.  
  382.         call writeln(handle, 'FILENAME=' || log.filename)
  383.         call writeln(handle, 'ALTFILENAME=' || log.altfilename)
  384.  
  385.         call writeln(handle, 'RETURNNUMBER=' || log.returnnumber)
  386.         call writeln(handle, 'RETURNSENDFUNC=' || log.returnsendfunc)
  387.         call writeln(handle, 'RETURNSTATUS=' || log.returnstatus)
  388.  
  389.         call writeln(handle, 'RETURNRETRY=' || log.returnretry)
  390.         call writeln(handle, 'RETURNINTERVAL=' || log.returninterval)
  391.  
  392.         call close(handle)
  393.         address rexx 'broadcast' 'refreshmailboxentry' mailbox handle
  394.     end; else call showDebugger('Could not update' logFile(mailbox, handle))
  395.  
  396.     return
  397.  
  398.  
  399.  
  400. showDebugger: procedure
  401.     if arg() ~= 1 then do
  402.         say "showDebugger: ERROR"
  403.         exit 20
  404.     end
  405.  
  406.     parse arg debuggerInfo
  407.     
  408.     firstLine = sourceline(1)
  409.     parse var firstLine '/*' 'TITLE:' title '*/'
  410.     if showlist('p', 'AVMLOGGER') then
  411.         address 'AVMLOGGER' 'add' title ':' debuggerInfo
  412.     else
  413.         say title ':' debuggerInfo
  414.  
  415.     return 
  416.  
  417. /*-----------------------------------------------------------------------*/
  418. /*                         signal processing                             */
  419.  
  420. arexxerror:
  421. error:
  422.     call showDebugger("Error" rc "at line" sigl)
  423.     exit 20
  424.  
  425. break_c:
  426. halt:
  427.     call showDebugger("Halt/Break_C at line" sigl)
  428.     exit 20
  429.  
  430. novalue:
  431.     call showDebugger("No value at line" sigl)
  432.     exit 20
  433.  
  434. syntax:
  435.     call showDebugger("Syntax error" rc "at line" sigl)
  436.     exit 20
  437.  
  438. exit
  439.  
  440. /* this requires logfunctions.avm */
  441.  
  442. loadMailbox: procedure expose mailbox.
  443.     if arg() ~= 1 then do
  444.         rc = "loadMailbox: bad args"
  445.         signal error
  446.     end
  447.  
  448.         mailbox. = ''
  449.     parse arg mailbox
  450.  
  451.     handle = 'mailboxconfig'
  452.     opened = open(handle, mailboxDir(mailbox) || 'mailbox.cfg', 'r')
  453.     if opened then do
  454.         do while ~eof(handle)
  455.             line = readln(handle)
  456.             parse upper var line variable '=' value
  457.             mailbox.variable = value
  458.         end
  459.         call close(handle)
  460.     end
  461.     return
  462.  
  463. /* pass a handle here */
  464. saveMailbox: procedure expose mailbox.
  465.     if arg() ~= 1 then do
  466.         rc = "saveMailbox: bad args"
  467.         signal error
  468.     end
  469.     parse arg mailbox
  470.  
  471.     handle = 'mailboxconfig'
  472.     opened = open(handle, mailboxDir(mailbox) || 'mailbox.cfg', 'w')
  473.  
  474.     if opened then do
  475.         call writeln(handle, 'PASSWORD=' || mailbox.password)
  476.  
  477.         call writeln(handle, 'AUTOFAXFORWARDB=' || mailbox.autofaxforwardb)
  478.         call writeln(handle, 'AUTOFAXFORWARD=' || mailbox.autofaxforward)
  479.         call writeln(handle, 'AUTOFAXFORWARDSCRIPT=' || mailbox.autofaxforwardscript)
  480.  
  481.         call writeln(handle, 'AUTOFORWARDB=' || mailbox.autoforwardb)
  482.         call writeln(handle, 'AUTOFORWARDONDEMAND=' || mailbox.autoforwardondemand)
  483.         call writeln(handle, 'AUTOFORWARD=' || mailbox.autoforward)
  484.         call writeln(handle, 'AUTOFORWARDSCRIPT=' || mailbox.autoforwardscript)
  485.  
  486.         call writeln(handle, 'AUTOPAGEB=' || mailbox.autopageb)
  487.         call writeln(handle, 'AUTOPAGEONDEMAND=' || mailbox.autopageondemand)
  488.         call writeln(handle, 'AUTOPAGE=' || mailbox.autopage)
  489.         call writeln(handle, 'AUTOPAGESCRIPT=' || mailbox.autopagescript)
  490.  
  491.         call writeln(handle, 'AUTOALERTB=' || mailbox.autoalertb)
  492.         call writeln(handle, 'AUTOALERTONDEMAND=' || mailbox.autoalertondemand)
  493.         call writeln(handle, 'AUTOALERTSCRIPT=' || mailbox.autoalertscript)
  494.  
  495.         call close(handle)
  496.     end
  497.  
  498.     return
  499.  
  500. stdabort:
  501. exit
  502.  
  503. stdbusy:
  504. exit
  505.  
  506. stderror:
  507. exit
  508.  
  509. stdtimedout:
  510. exit
  511.  
  512. stdfaxinstruct:
  513. 'playvoice' 'avm:voices/FaxStarting'
  514. action = rc
  515. select
  516.   when action = 0 then nop
  517.   when action = 1 then do; call checkifabort; end
  518.   when action = 4 then nop
  519.   when action = 5 then nop
  520.   when action = 8 then signal stdbusy
  521.   when action = 12 then signal stdabort
  522.   when action = 14 then nop
  523.   when action = 16 then nop
  524.   otherwise signal arexxerror
  525. end
  526.  
  527. stdfax:
  528. faxscript = getclip(address() || 'FAXSCRIPT')
  529. if faxscript = '' then faxscript = 'handlefax'
  530. if symbol('mailbox') = 'VAR' then address rexx faxscript address() mailbox
  531. else address rexx faxscript address() 'anonymous'
  532. exit
  533.  
  534. stddatainstruct:
  535. 'playvoice' 'avm:voices/DataStarting'
  536. action = rc
  537. select
  538.   when action = 0 then nop
  539.   when action = 1 then do; call checkifabort; end
  540.   when action = 4 then nop
  541.   when action = 5 then nop
  542.   when action = 8 then signal stdbusy
  543.   when action = 12 then signal stdabort
  544.   when action = 14 then nop
  545.   when action = 16 then nop
  546.   otherwise signal arexxerror
  547. end
  548.  
  549. stddata:
  550. datascript = getclip(address() || 'DATASCRIPT')
  551. if datascript = '' then datascript = 'handledata'
  552. if symbol('mailbox') = 'VAR' then address rexx datascript address() mailbox
  553. else address rexx datascript address()
  554. exit
  555.  
  556. checkifabort:
  557. 'readnkeys' '1' '3'
  558. action = rc
  559. if action = 0 then value = result
  560. select
  561.   when action = 0 then do; if value = '*' then signal stdabort; end
  562.   when action = 4 then nop
  563.   when action = 5 then nop
  564.   when action = 8 then signal stdbusy
  565.   when action = 10 then nop
  566.   when action = 12 then signal stdabort
  567.   when action = 14 then signal stderror
  568.   when action = 16 then signal stderror
  569.   otherwise signal arexxerror
  570. end
  571. return
  572.  
  573.  
  574.